function autoRowSpan(tb, cidx, ridx) 
{ 
  var lastValue = "";
  var value = "";
  var pos = 1;
  for(var col = cidx; col >= 0; col--) {
    pos = 1;
    for(var i = ridx; i < tb.rows.length; i++) {
      value = tb.rows[i].cells[col].innerText;
      if(lastValue == value && tb.rows[i - pos].cells[0].innerText == tb.rows[i].cells[0].innerText) {
        tb.rows[i].deleteCell(col);
        tb.rows[i - pos].cells[col].rowSpan = tb.rows[i - pos].cells[col].rowSpan + 1;
        pos++;
        } else { 
          lastValue = value;
          pos = 1;
      }
    }
  }
}

function autoRowSpanTables(tb1, cidx1, ridx1, tb2, cidx2, ridx2) 
{ 
  var lastValue = "";
  var value = "";
  var pos = 1;
  var lastValue2 = "";
  var value2 = "";
  var pos2 = 1;

  for(var col = cidx1; col >= 0; col--) {
    pos = 1;
    for(var i = ridx1; i < tb1.rows.length; i++) {
      value = tb1.rows[i].cells[col].innerText;
      if(lastValue == value && tb1.rows[i - pos].cells[0].innerText == tb1.rows[i].cells[0].innerText) {
        tb1.rows[i].deleteCell(col);
        tb1.rows[i - pos].cells[col].rowSpan = tb1.rows[i - pos].cells[col].rowSpan + 1;
        pos++;
        } else { 
          lastValue = value;
          pos = 1;
      }
    }
  }
  
  for(var col = cidx2; col >= 0; col--) {
    pos2 = 1;
    for(var i = ridx2; i < tb2.rows.length; i++) {
      value2 = tb2.rows[i].cells[col].innerText;
      if(lastValue2 == value2 && tb2.rows[i - pos2].cells[0].innerText == tb2.rows[i].cells[0].innerText) {
        tb2.rows[i].deleteCell(col);
        tb2.rows[i - pos2].cells[col].rowSpan = tb2.rows[i - pos2].cells[col].rowSpan + 1;
        pos2++;
        } else { 
          lastValue2 = value2;
          pos2 = 1;
      }
    }
  }
}